//
//  ServiceCompileViewController.m
//  HondaPro_2
//
//  Created by ht on 13-7-2.
//  Copyright (c) 2013年 glendale. All rights reserved.
//

#import "ServiceCompileViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "UIViewController+MJPopupViewController.h"
#import "ServiceAssignedViewController.h"
#import "webConfig.h"
#import "webService.h"
@interface ServiceCompileViewController ()
{
    ServiceCompileViewController *_svc;
}
@end

@implementation ServiceCompileViewController

@synthesize serviceNumber = _serviceNumber;//维修单
@synthesize beginTimeButton = _beginTimeButton;  //预计开始时间
@synthesize realityEndTime = _realityEndTime; //实际结束时间
@synthesize endTimeButton = _endTimeButton;      //预计结束时间
@synthesize realityBeginTime = _realityBeginTime;  //实际开始时间
@synthesize workshopButton = _workshopButton;     //工场
@synthesize stationButton = _stationButton;       //工位

@synthesize receiveLabel = _receiveLabel;   //接待员
@synthesize comeTime = _comeTime; //来厂时间
@synthesize realityTaskTime = _realityTaskTime;//实际工时
@synthesize payCarTime = _payCarTime;   //交车时间
@synthesize checkTaskTime = _checkTaskTime; //考核工时
@synthesize maintainTypeLabel = _maintainTypeLabel;//维修分类
@synthesize maintainTeacherButton = _maintainTeacherButton;//维修师

@synthesize carPlateField = _carPlateField;
@synthesize carFrameField = _carFrameField;
@synthesize datePicker = _datePicker;
@synthesize popoverCtl = _popoverCtl;

@synthesize determineButton = _determineButton;
//选择器
@synthesize yuyueDate = _yuyueDate;
//传日期时间的代理
@synthesize delegate = _delegate;
@synthesize editDataDit = _editDataDit;

@synthesize receiveDit = _receiveDit;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        [self addNotification];
    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setFrame:CGRectMake(100, 0, 800, 720)];
    
    [self loadfixedlabel];//固定标题
    [self loadCallButtonPicture];//要调用的button
    [self loadTextField];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    //remove observer
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 所有下拉菜单按钮
-(void)loadCallButtonPicture
{
    //维修单
    self.serviceNumber = [[UILabel alloc]initWithFrame:CGRectMake(145, 90, 225, 35)];
    self.serviceNumber.textColor = [UIColor grayColor];
    [self.serviceNumber setBackgroundColor:[UIColor clearColor]];
    self.serviceNumber.text = [self.receiveDit valueForKey:@"jobSheetId"];
    self.serviceNumber.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.serviceNumber.layer.borderColor = [[UIColor grayColor]CGColor];
    self.serviceNumber.layer.borderWidth = 0.8;
    [self.serviceNumber setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.serviceNumber];
    
    //预计开始时间菜单
    self.beginTimeButton = [[UIButton alloc]initWithFrame:CGRectMake(143, 147, 230, 41)];
    [self.beginTimeButton setBackgroundImage:[UIImage imageNamed:@"10.png"] forState:UIControlStateNormal];
    [self.beginTimeButton addTarget:self action:@selector(beginTimeButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.beginTimeButton setTitle:@"<  空  >" forState:UIControlStateNormal];
    [self.beginTimeButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    self.beginTimeButton.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:self.beginTimeButton];
    UILabel *beginTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(145, 150, 225, 35)];
    beginTimeLabel.textColor = [UIColor blackColor];
    [beginTimeLabel setBackgroundColor:[UIColor clearColor]];
    beginTimeLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    beginTimeLabel.layer.borderWidth = 0.8;
    [self.view addSubview:beginTimeLabel];
    
    //实际开始时间
    self.realityBeginTime = [[UILabel alloc]initWithFrame:CGRectMake(145, 210, 225, 35)];
    self.realityBeginTime.textColor = [UIColor grayColor];
    [self.realityBeginTime setBackgroundColor:[UIColor clearColor]];
    self.realityBeginTime.text = [self.receiveDit valueForKey:@"realStartTime"];
    self.realityBeginTime.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.realityBeginTime.layer.borderColor = [[UIColor grayColor]CGColor];
    self.realityBeginTime.layer.borderWidth = 0.8;
    [self.realityBeginTime setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.realityBeginTime];
    
    //工场菜单
    self.workshopButton = [[UIButton alloc]initWithFrame:CGRectMake(143, 267, 230, 41)];
    [self.workshopButton setBackgroundImage:[UIImage imageNamed:@"10.png"] forState:UIControlStateNormal];
    [self.workshopButton addTarget:self action:@selector(workshopButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.workshopButton setTitle:@"修理工场" forState:UIControlStateNormal];
    [self.workshopButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.workshopButton];
    self.gChangNumber = @"0";
    UILabel *workshopLabel = [[UILabel alloc]initWithFrame:CGRectMake(145, 270, 225, 35)];
    workshopLabel.textColor = [UIColor blackColor];
    [workshopLabel setBackgroundColor:[UIColor clearColor]];
    workshopLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    workshopLabel.layer.borderWidth = 0.8;
    [self.view addSubview:workshopLabel];
    
    //预计结束时间菜单
    self.endTimeButton = [[UIButton alloc]initWithFrame:CGRectMake(513, 147, 230, 41)];
    [self.endTimeButton setBackgroundImage:[UIImage imageNamed:@"10.png"] forState:UIControlStateNormal];
    [self.endTimeButton addTarget:self action:@selector(endTimeButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.endTimeButton setTitle:@"<  空  >" forState:UIControlStateNormal];
    [self.endTimeButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    self.endTimeButton.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.beginTimeButton setTag:10];
    [self.view addSubview:self.endTimeButton];
    UILabel *endTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(515, 150, 225, 35)];
    endTimeLabel.textColor = [UIColor blackColor];
    [endTimeLabel setBackgroundColor:[UIColor clearColor]];
    endTimeLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    endTimeLabel.layer.borderWidth = 0.8;
    [self.view addSubview:endTimeLabel];

    //实际结束时间菜单
    self.realityEndTime = [[UILabel alloc]initWithFrame:CGRectMake(515, 210, 225, 35)];
    self.realityEndTime.textColor = [UIColor grayColor];
    [self.realityEndTime setBackgroundColor:[UIColor clearColor]];
    self.realityEndTime.text = [self.receiveDit valueForKey:@"realEndTime"];
    self.realityEndTime.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.realityEndTime.layer.borderColor = [[UIColor grayColor]CGColor];
    self.realityEndTime.layer.borderWidth = 0.8;
    [self.realityEndTime setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.realityEndTime];
    
    //工位菜单
    self.stationButton = [[UIButton alloc]initWithFrame:CGRectMake(513, 267, 230, 41)];
    [self.stationButton setBackgroundImage:[UIImage imageNamed:@"10.png"] forState:UIControlStateNormal];
    [self.stationButton setTitle:@"请选择" forState:UIControlStateNormal];
    [self.stationButton addTarget:self action:@selector(stationButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.stationButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.stationButton];
    UILabel *stationLabel = [[UILabel alloc]initWithFrame:CGRectMake(515, 270, 225, 35)];
    stationLabel.textColor = [UIColor blackColor];
    [stationLabel setBackgroundColor:[UIColor clearColor]];
    stationLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    stationLabel.layer.borderWidth = 0.8;
    [self.view addSubview:stationLabel];
    
    //接待员菜单
    self.receiveLabel = [[UILabel alloc]initWithFrame:CGRectMake(145, 350, 225, 35)];
    self.receiveLabel.textColor = [UIColor grayColor];
    [self.receiveLabel setBackgroundColor:[UIColor clearColor]];
    self.receiveLabel.text = [self.receiveDit valueForKey:@"evaluatorName"];
    self.receiveLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.receiveLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    self.receiveLabel.layer.borderWidth = 0.8;
    [self.receiveLabel setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.receiveLabel];
    
    //来厂时间
    self.comeTime = [[UILabel alloc]initWithFrame:CGRectMake(145, 410, 225, 35)];
    self.comeTime.textColor = [UIColor grayColor];
    [self.comeTime setBackgroundColor:[UIColor clearColor]];
    self.comeTime.text = [self.receiveDit valueForKey:@"comingDate"];
    self.comeTime.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.comeTime.layer.borderColor = [[UIColor grayColor]CGColor];
    self.comeTime.layer.borderWidth = 0.8;
    [self.comeTime setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.comeTime];
    
    //实际工时
    self.realityTaskTime = [[UILabel alloc]initWithFrame:CGRectMake(145, 470, 225, 35)];
    self.realityTaskTime.textColor = [UIColor grayColor];
    [self.realityTaskTime setBackgroundColor:[UIColor clearColor]];
//    self.realityTaskTime.text = [self.receiveDit valueForKey:@"jobSheetId"];
    self.realityTaskTime.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.realityTaskTime.layer.borderColor = [[UIColor grayColor]CGColor];
    self.realityTaskTime.layer.borderWidth = 0.8;
    [self.realityTaskTime setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.realityTaskTime];

    //维修分类
    self.maintainTypeLabel = [[UILabel alloc]initWithFrame:CGRectMake(145, 530, 225, 35)];
    self.maintainTypeLabel.textColor = [UIColor grayColor];
    [self.maintainTypeLabel setBackgroundColor:[UIColor clearColor]];
    self.maintainTypeLabel.text = [self.receiveDit valueForKey:@"repairTypeName"];
    self.maintainTypeLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.maintainTypeLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    self.maintainTypeLabel.layer.borderWidth = 0.8;
    [self.maintainTypeLabel setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.maintainTypeLabel];
    
    //预计交车时间
    self.payCarTime = [[UILabel alloc]initWithFrame:CGRectMake(515, 410, 225, 35)];
    self.payCarTime.textColor = [UIColor grayColor];
    [self.payCarTime setBackgroundColor:[UIColor clearColor]];
    self.payCarTime.text = [self.receiveDit valueForKey:@"deliveryPlannedDate"];
    self.payCarTime.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.payCarTime.layer.borderColor = [[UIColor grayColor]CGColor];
    self.payCarTime.layer.borderWidth = 0.8;
    [self.payCarTime setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.payCarTime];
    
    //考核工时
    self.checkTaskTime = [[UILabel alloc]initWithFrame:CGRectMake(515, 470, 225, 35)];
    self.checkTaskTime.textColor = [UIColor grayColor];
    [self.checkTaskTime setBackgroundColor:[UIColor clearColor]];
    self.checkTaskTime.text = [self.receiveDit valueForKey:@"checkWorkHour"];
    self.checkTaskTime.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.checkTaskTime.layer.borderColor = [[UIColor grayColor]CGColor];
    self.checkTaskTime.layer.borderWidth = 0.8;
    [self.checkTaskTime setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.checkTaskTime];
    
    //维修师
    self.maintainTeacherButton = [[UIButton alloc]initWithFrame:CGRectMake(513, 527, 230, 41)];
    [self.maintainTeacherButton setBackgroundImage:[UIImage imageNamed:@"10.png"] forState:UIControlStateNormal];
    [self.maintainTeacherButton addTarget:self action:@selector(maintainTeacherButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.maintainTeacherButton setTitle:@"请选择" forState:UIControlStateNormal];
    [self.maintainTeacherButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.view addSubview:self.maintainTeacherButton];
    UILabel *maintainTeacherLabel = [[UILabel alloc]initWithFrame:CGRectMake(515, 530, 225, 35)];
    maintainTeacherLabel.textColor = [UIColor blackColor];
    [maintainTeacherLabel setBackgroundColor:[UIColor clearColor]];
    maintainTeacherLabel.layer.borderColor = [[UIColor grayColor]CGColor];
    maintainTeacherLabel.layer.borderWidth = 0.8;
    [self.view addSubview:maintainTeacherLabel];
#pragma mark - 确定按钮
    self.determineButton = [[UIButton alloc]initWithFrame:CGRectMake(680, 620, 75, 34)];
    [self.determineButton setBackgroundImage:[UIImage imageNamed:@"ht05-1.png"] forState:UIControlStateNormal];
    [self.determineButton setTitle:@"确 定" forState:UIControlStateNormal];
    [self.determineButton setTintColor:[UIColor whiteColor]];
    self.determineButton.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
    [self.determineButton addTarget:self action:@selector(determineButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.determineButton];
}
-(void)loadTextField
{
    self.carPlateField = [[UILabel alloc]initWithFrame:CGRectMake(515, 90, 225, 35)];//车牌号
    self.carPlateField.textColor = [UIColor grayColor];
    [self.carPlateField setBackgroundColor:[UIColor clearColor]];
    self.carPlateField.text = [self.receiveDit valueForKey:@"plateNumber"];
    self.carPlateField.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.carPlateField.layer.borderColor = [[UIColor grayColor]CGColor];
    self.carPlateField.layer.borderWidth = 0.8;
    [self.carPlateField setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.carPlateField];
    
    self.carFrameField = [[UILabel alloc]initWithFrame:CGRectMake(515, 350, 225, 35)];   //车架号
    self.carFrameField.textColor = [UIColor grayColor];
    [self.carFrameField setBackgroundColor:[UIColor clearColor]];
    self.carFrameField.text = [self.receiveDit valueForKey:@"vin"];
    self.carFrameField.font = [UIFont fontWithName:@"ArialMT" size:15];
    self.carFrameField.layer.borderColor = [[UIColor grayColor]CGColor];
    self.carFrameField.layer.borderWidth = 0.8;
    [self.carFrameField setTextAlignment:NSTextAlignmentCenter];
    [self.view addSubview:self.carFrameField];
}
#pragma mark - 预计开始时间的回调
-(void)beginTimeButton:(id)sender
{
    if (self.popController.popoverVisible)
    {
        [self.popController dismissPopoverAnimated:YES];
        return;
    }
    self.popoverCtl = [[UIViewController alloc] init];
    self.popoverCtl.view.backgroundColor = [UIColor yellowColor];
    self.popController = [[UIPopoverController alloc] initWithContentViewController:self.popoverCtl];
    self.popController.popoverContentSize = CGSizeMake(310.0f, 160.0f);
    [self.popController presentPopoverFromRect:CGRectMake(0, 0, 215, 40) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    self.yuyueDate = self.datePicker.date;
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 310, 160)];
    self.datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"Chinese", @"")];
    self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    [self.popoverCtl.view addSubview:self.datePicker];
    [self.datePicker addTarget:self action:@selector(dateChanged1:) forControlEvents:UIControlEventValueChanged];
}
-(void)dateChanged1:(id)sender
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    self.yuyueDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:self.datePicker.date]];

    
    [self.beginTimeButton setTitle:[NSString stringWithFormat:@"%@",self.yuyueDate] forState:UIControlStateNormal];
    
    [self.endTimeButton setTitle:[formatter stringFromDate:[self.datePicker.date addTimeInterval:1*3600]] forState:UIControlStateNormal];
}
#pragma mark - 预计结束时间的回调
-(void)endTimeButton:(id)sender
{
    if (self.popController.popoverVisible)
    {
        [self.popController dismissPopoverAnimated:YES];
        return;
    }
    self.popoverCtl = [[UIViewController alloc] init];
    self.popoverCtl.view.backgroundColor = [UIColor yellowColor];
    self.popController = [[UIPopoverController alloc] initWithContentViewController:self.popoverCtl];
    self.popController.popoverContentSize = CGSizeMake(310.0f, 160.0f);
    [self.popController presentPopoverFromRect:CGRectMake(0, 0, 215, 40) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    self.yuyueDate = self.datePicker.date;
    self.datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 0, 310, 160)];
    self.datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:NSLocalizedString(@"Chinese", @"")];
    self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    [self.datePicker setDate:[formatter dateFromString:self.self.endTimeButton.titleLabel.text]];
    
    [self.datePicker addTarget:self action:@selector(dateChanged2:) forControlEvents:UIControlEventValueChanged];
    [self.popoverCtl.view addSubview:self.datePicker];
}
-(void)dateChanged2:(id)sender
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    self.yuyueDate = [NSString stringWithFormat:@"%@",[formatter stringFromDate:self.datePicker.date]];
    [self.endTimeButton setTitle:[NSString stringWithFormat:@"%@",self.yuyueDate] forState:UIControlStateNormal];
}

#pragma mark - 工场选择的回调
-(void)workshopButton:(id)sender
{
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.workshopButton.frame.size.width, 120)];
    [self.popCon presentPopoverFromRect:CGRectMake(55, 15, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    
    self.gChangXZ = [[NSMutableArray alloc] init];
    [self.gChangXZ addObject:@"修理工场"];
    [self.gChangXZ addObject:@"钣金工场"];
    [self.gChangXZ addObject:@"喷漆工场"];
    contentCon.list = self.gChangXZ;
    [contentCon.myTableView reloadData];
}
#pragma mark - 工位选择的回调
-(void)stationButton:(id)sender
{
    webService *webcon = [[webService alloc] init];
    webcon.methodName = GETWORKSTATIONLIST;
    NSMutableArray *arry = [NSMutableArray arrayWithObjects:@"workshopType",self.gChangNumber,nil];
    
    [webcon commonGetSharedRequest:GETWORKSTATIONLIST wsparas:arry];
    
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.stationButton.frame.size.width, 280)];
    [self.popCon presentPopoverFromRect:CGRectMake(55, 10, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
-(void)getworkStationList:(NSNotification*)notification
{
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.workStationArray = [theJson objectForKey:@"workStationList"];
    NSMutableArray *gWeiArray = [[NSMutableArray alloc]init];
    for(int i=0;i<[[theJson objectForKey:@"workStationList"]count];i++)
    {
        [gWeiArray addObject:[[[theJson objectForKey:@"workStationList"]objectAtIndex:i]objectForKey:@"workStationName"]];
    }
    contentCon.list = gWeiArray;
    [contentCon.myTableView reloadData];
}

#pragma mark - 维修师选择的回调
-(void)maintainTeacherButton:(id)sender
{
    webService *webcon = [[webService alloc] init];
    webcon.methodName = GETREPAIRPERSONLIST;    
    [webcon commonGetSharedRequest:GETREPAIRPERSONLIST wsparas:nil];
    
    if (!contentCon) {
        contentCon=[[popContentViewController alloc] initWithNibName:@"popContentViewController" bundle:nil];
    }
    contentCon.delegate = self;
    contentCon.btnSender=sender;
    self.popCon = [[UIPopoverController alloc] initWithContentViewController:contentCon];
    [DDPopoverBackgroundView setTintColor:[UIColor colorWithRed:234 green:248 blue:242 alpha:0.9]];
    [DDPopoverBackgroundView setArrowBase:30.0];//箭头
    [DDPopoverBackgroundView setArrowHeight:15.0];
    [DDPopoverBackgroundView setContentInset:1.0];
    [self.popCon setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
    [self.popCon setPopoverContentSize:CGSizeMake(self.maintainTeacherButton.frame.size.width, 280)];
    [self.popCon presentPopoverFromRect:CGRectMake(55, 10, 120, 20) inView:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
-(void)getRepairPersonList:(NSNotification*)notification
{
    NSDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData*)notification.object options:NSJSONReadingMutableLeaves error:Nil];
    self.repairPersonArray = [theJson objectForKey:@"results"];
    NSMutableArray *weixiushi = [[NSMutableArray alloc]init];
    for(int i=0;i<[[theJson objectForKey:@"results"]count];i++)
    {
        [weixiushi addObject:[[[theJson objectForKey:@"results"]objectAtIndex:i]objectForKey:@"repairPersonName"]];
    }
    contentCon.list = nil;
    contentCon.list = weixiushi;
    [contentCon.myTableView reloadData];
}
//弹出回调方法
-(void)selectDelegate:(NSInteger)row btn:(UIButton *)btn
{
    if(btn == self.stationButton)
    {
        self.workStationNameId = [[self.workStationArray objectAtIndex:row]objectForKey:@"workStationId"];
        self.workStationRow = [NSString stringWithFormat:@"%d",row];
    }
    if(btn == self.maintainTeacherButton)
    {
        self.repairPersonId = [[self.repairPersonArray objectAtIndex:row]objectForKey:@"repairPersonId"];
//        NSLog(@"~>~>~>~>~%@",self.repairPersonId);
    }
        
    if(btn == self.workshopButton)
    {
        if([[self.gChangXZ objectAtIndex:row] isEqualToString:@"修理工场"])
        {
            self.gChangNumber = @"0";
        }
        if([[self.gChangXZ objectAtIndex:row] isEqualToString:@"钣金工场"])
        {
            self.gChangNumber = @"1";
        }
        if([[self.gChangXZ objectAtIndex:row] isEqualToString:@"喷漆工场"])
        {
            self.gChangNumber = @"2";
        }
    }
    [self.popCon dismissPopoverAnimated:YES];
    self.popCon = nil;
} 

-(void)shujuDictionary
{
    self.editDataDit = [[NSMutableDictionary alloc]initWithCapacity:10];
    [self.editDataDit setObject:self.serviceNumber.text forKey:@"jobSheetId"];//作业单号
    [self.editDataDit setObject:self.carPlateField.text forKey:@"plateNumber"];//车牌
    [self.editDataDit setObject:self.beginTimeButton.titleLabel.text forKey:@"estimatedStartTime"];//预计开始时间
    [self.editDataDit setObject:self.workshopButton.titleLabel.text forKey:@"factoryName"];//工场
    if(![self.stationButton.titleLabel.text isEqualToString:@"请选择"])
    {
        [self.editDataDit setObject:self.workStationNameId forKey:@"workStationId"];//工位id
    }
    [self.editDataDit setObject:self.endTimeButton.titleLabel.text forKey:@"estimatedEndTime"];//预计结束时间
//    [self.editDataDit setObject:self.stationButton.titleLabel.text forKey:@"workStationName"];
    [self.editDataDit setObject:self.receiveLabel.text forKey:@"evaluatorName"];//接待员
    [self.editDataDit setObject:self.maintainTypeLabel.text forKey:@"repairTypeName"];//维修分类
    [self.editDataDit setObject:self.payCarTime.text forKey:@"deliveryPlannedDate"];//预计交车时间
//    [self.editDataDit setObject:self.maintainTeacherButton.titleLabel.text forKey:@"repairerName"];//维修师
    if (self.repairPersonId==nil)
    {
    }
    if(![self.maintainTeacherButton.titleLabel.text isEqualToString:@"请选择"])
    {
        [self.editDataDit setObject:self.repairPersonId forKey:@"repairPersonId"];//维修师Id
    }
    [self.editDataDit setObject:self.carFrameField.text forKey:@"vin"];//车架号
//    [self.editDataDit setObject:paigong forKey:@"itemNo"];//派工号
//    NSLog(@"#########%@",self.stationButton.titleLabel.text);
}
#pragma mark - 确定按钮的回调
-(void)determineButton:(id)sender
{
    NSString *strOne = self.beginTimeButton.titleLabel.text;
    if([strOne isEqualToString:@"<  空  >"])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请选择预计开始日期" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
    }
    else if([self.endTimeButton.titleLabel.text isEqualToString:@"<  空  >"])
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请选择预计结束日期" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
    }
    else
    {
        //获取当前时间换算成秒
        NSTimeZone *zone = [NSTimeZone defaultTimeZone];//获得当前应用程序默认的时区
        NSInteger interval = [zone secondsFromGMTForDate:[NSDate date]];//以秒为单位返回当前应用程序与世界标准时间（格林威尼时间）的时差
        NSDate *localeDate = [[NSDate date] dateByAddingTimeInterval:interval];
        NSTimeInterval timeInterval2 = [localeDate timeIntervalSince1970];
        //获取选择器时间换算成秒
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm"];
        NSDate *destDate= [dateFormatter dateFromString:strOne];
        NSDate *localeDate1 = [destDate dateByAddingTimeInterval:interval];
        NSTimeInterval timeInterval1 = [localeDate1 timeIntervalSince1970];
//        NSLog(@"****%f",timeInterval1);
//        NSLog(@"%f",timeInterval2);
        if(timeInterval1 < timeInterval2)
        {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"预计开始时间不能小于当前时间" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
            [alertView show];
        }
        else
        {            
//            [self.delegate passTime:self.editDataDit];
//            [self.delegate cancelButtonClicked:self];
            webService *web = [[webService alloc]init];
            web.methodName = CREATEJOBDISPATCHING;
            [self shujuDictionary];
//            NSLog(@"~？~？~？~？~？~？~？~ %@",self.editDataDit);
            [web commonPostSharedRequest:CREATEJOBDISPATCHING psotDic:self.editDataDit];
        }
    }
}
-(void)createJobDispatching:(NSNotification*)notification
{
    NSMutableDictionary *theJson = [NSJSONSerialization JSONObjectWithData:(NSData *)notification.object options:NSJSONReadingMutableLeaves error:nil];
    if([[theJson valueForKey:@"error_code"] intValue])
    {
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[theJson valueForKey:@"error_msg"] message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alertView show];
        
        return;
    }
    else
    {
        _zJiaPgongDit = [[NSMutableDictionary alloc]initWithCapacity:10];
        [_zJiaPgongDit setObject:self.serviceNumber.text forKey:@"jobSheetId"];
        [_zJiaPgongDit setObject:self.carPlateField.text forKey:@"plateNumber"];
        [_zJiaPgongDit setObject:self.receiveLabel.text forKey:@"evaluatorName"];
        [_zJiaPgongDit setObject:self.beginTimeButton.titleLabel.text forKey:@"estimatedStartTime"];
        [_zJiaPgongDit setObject:self.endTimeButton.titleLabel.text forKey:@"estimatedEndTime"];
        [_zJiaPgongDit setObject:self.workshopButton.titleLabel.text forKey:@"factoryName"];
        [_zJiaPgongDit setObject:self.workStationRow forKey:@"row"];
//        [_zJiaPgongDit setObject:paigong forKey:@"itemNo"];

        //通过代理传字典
        [self.delegate passTime:_zJiaPgongDit];
//        NSLog(@"绘制图标需要的字典：%@",_zJiaPgongDit);
        [self.delegate cancelButtonClicked:self];
        
        [self removeNotification];
    }
}
#pragma mark - 界面固定图片和标题
-(void)loadfixedlabel
{
    UILabel *imagetitel = [[UILabel alloc]initWithFrame:CGRectMake(30, 25, 120, 35)];
    imagetitel.text = @"派工编辑";
    imagetitel.backgroundColor = [UIColor clearColor];
    imagetitel.textColor = [UIColor grayColor];
    imagetitel.font = [UIFont fontWithName:@"Verdana-Bold" size:20];
    [self.view addSubview:imagetitel];
    
    UIImageView *imageline= [[UIImageView alloc]initWithFrame:CGRectMake(15, 65, 770, 3)];
    imageline.image = [UIImage imageNamed:@"红色分割线.png"];
    [self.view addSubview:imageline];
    
    UIImageView *imageline1= [[UIImageView alloc]initWithFrame:CGRectMake(0, 320, 800, 5)];
    imageline1.image = [UIImage imageNamed:@"渐变分割线.png"];
    [self.view addSubview:imageline1];
    
    UILabel *fixed1 = [[UILabel alloc]initWithFrame:CGRectMake(30, 90, 120, 35)];
    fixed1.text = @"维     修     单:";
    fixed1.backgroundColor = [UIColor clearColor];
    fixed1.textColor = [UIColor grayColor];
    fixed1.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed1];
    
    UILabel *fixed2 = [[UILabel alloc]initWithFrame:CGRectMake(30, 150, 120, 35)];
    fixed2.text = @"预计开始时间:";
    fixed2.backgroundColor = [UIColor clearColor];
    fixed2.textColor = [UIColor grayColor];
    fixed2.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed2];
    
    UILabel *fixed3 = [[UILabel alloc]initWithFrame:CGRectMake(30, 210, 120, 35)];
    fixed3.text = @"实际开始时间:";
    fixed3.backgroundColor = [UIColor clearColor];
    fixed3.textColor = [UIColor grayColor];
    fixed3.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed3];
    
    UILabel *fixed4 = [[UILabel alloc]initWithFrame:CGRectMake(30, 270, 120, 35)];
    fixed4.text = @"工              场:";
    fixed4.backgroundColor = [UIColor clearColor];
    fixed4.textColor = [UIColor grayColor];
    fixed4.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed4];
    
    UILabel *fixed5 = [[UILabel alloc]initWithFrame:CGRectMake(400, 90, 120, 35)];
    fixed5.text = @"车     牌     号:";
    fixed5.backgroundColor = [UIColor clearColor];
    fixed5.textColor = [UIColor grayColor];
    fixed5.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed5];
    
    UILabel *fixed6 = [[UILabel alloc]initWithFrame:CGRectMake(400, 150, 120, 35)];
    fixed6.text = @"预计结束时间:";
    fixed6.backgroundColor = [UIColor clearColor];
    fixed6.textColor = [UIColor grayColor];
    fixed6.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed6];
    
    UILabel *fixed7 = [[UILabel alloc]initWithFrame:CGRectMake(400, 210, 120, 35)];
    fixed7.text = @"实际结束时间:";
    fixed7.backgroundColor = [UIColor clearColor];
    fixed7.textColor = [UIColor grayColor];
    fixed7.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed7];
    
    UILabel *fixed8 = [[UILabel alloc]initWithFrame:CGRectMake(400, 270, 120, 35)];
    fixed8.text = @"工              位:";
    fixed8.backgroundColor = [UIColor clearColor];
    fixed8.textColor = [UIColor grayColor];
    fixed8.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed8];
    
    UILabel *fixed9 = [[UILabel alloc]initWithFrame:CGRectMake(30, 350, 120, 35)];
    fixed9.text = @"接    待    员:";
    fixed9.backgroundColor = [UIColor clearColor];
    fixed9.textColor = [UIColor grayColor];
    fixed9.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed9];
    
    UILabel *fixed10 = [[UILabel alloc]initWithFrame:CGRectMake(30, 410, 120, 35)];
    fixed10.text = @"来  厂  时  间:";
    fixed10.backgroundColor = [UIColor clearColor];
    fixed10.textColor = [UIColor grayColor];
    fixed10.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed10];
    
    UILabel *fixed11 = [[UILabel alloc]initWithFrame:CGRectMake(30, 470, 120, 35)];
    fixed11.text = @"实  际  工  时:";
    fixed11.backgroundColor = [UIColor clearColor];
    fixed11.textColor = [UIColor grayColor];
    fixed11.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed11];
    
    UILabel *fixed12 = [[UILabel alloc]initWithFrame:CGRectMake(30, 530, 120, 35)];
    fixed12.text = @"维  修  类  型:";
    fixed12.backgroundColor = [UIColor clearColor];
    fixed12.textColor = [UIColor grayColor];
    fixed12.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed12];
    
    UILabel *fixed13 = [[UILabel alloc]initWithFrame:CGRectMake(400, 350, 120, 35)];
    fixed13.text = @"车     架     号:";
    fixed13.backgroundColor = [UIColor clearColor];
    fixed13.textColor = [UIColor grayColor];
    fixed13.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed13];
    
    UILabel *fixed14 = [[UILabel alloc]initWithFrame:CGRectMake(400, 410, 120, 35)];
    fixed14.text = @"预计交车时间:";
    fixed14.backgroundColor = [UIColor clearColor];
    fixed14.textColor = [UIColor grayColor];
    fixed14.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed14];
    
    UILabel *fixed15 = [[UILabel alloc]initWithFrame:CGRectMake(400, 470, 120, 35)];
    fixed15.text = @"考  核  工  时:";
    fixed15.backgroundColor = [UIColor clearColor];
    fixed15.textColor = [UIColor grayColor];
    fixed15.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed15];
    
    UILabel *fixed16 = [[UILabel alloc]initWithFrame:CGRectMake(400, 530, 120, 35)];
    fixed16.text = @"维     修     师:";
    fixed16.backgroundColor = [UIColor clearColor];
    fixed16.textColor = [UIColor grayColor];
    fixed16.font = [UIFont fontWithName:@"ArialMT" size:16];
    [self.view addSubview:fixed16];
    
}
-(void)addNotification
{
    //派工新增页面
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(createJobDispatching:) name:CREATEJOBDISPATCHING object:nil];
    //工位
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getworkStationList:) name:GETWORKSTATIONLIST object:Nil];
    //维修师
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getRepairPersonList:) name:GETREPAIRPERSONLIST object:Nil];
}
-(void)removeNotification
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
